﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterAdmin.master" AutoEventWireup="true" CodeBehind="Manufacture.aspx.cs" Inherits="Project_Udrinkwater.PagesAdmin.Manufacture" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <dx:ASPxRoundPanel ID="RPN_SalaryEmp" runat="server" Width="100%" 
         HeaderText="รายการสั่งผลิต">
        <HeaderStyle Font-Size="Medium" HorizontalAlign="Left" />
</dx:ASPxRoundPanel>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
                        Text="พิมพ์รายงาน" />
    <dx:ASPxGridView ID="MasterGV" runat="server" AutoGenerateColumns="False" 
        DataSourceID="dsOrder_Manufacture" KeyFieldName="Order_Manufacture_ID" 
        Width="100%">
        <Columns>
            <dx:GridViewCommandColumn VisibleIndex="6" Caption=" " 
                ShowSelectCheckbox="True">
                <EditButton Visible="True" Text="แก้ไข">
                </EditButton>
                <NewButton Visible="True" Text="เพิ่ม">
                </NewButton>
                <DeleteButton Visible="True" Text="ลบ">
                </DeleteButton>
                <ClearFilterButton Visible="True">
                </ClearFilterButton>
            </dx:GridViewCommandColumn>
            <dx:GridViewDataTextColumn FieldName="Order_Manufacture_ID" ReadOnly="True" 
                VisibleIndex="0" Visible="False">
                <EditFormSettings Visible="False">
                </EditFormSettings>
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="RowID" ReadOnly="True" VisibleIndex="1" 
                Caption="ลำดับ">
                <EditFormSettings Visible="False" />
                <HeaderStyle HorizontalAlign="Center" />
                <CellStyle HorizontalAlign="Center">
                </CellStyle>
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Order_Manufacture_doc_NO" 
                VisibleIndex="2" Caption="เลขที่การผลิต" ReadOnly="True">
                <EditFormSettings Visible="False" />
                <HeaderStyle HorizontalAlign="Center" />
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataComboBoxColumn Caption="พนักงาน" FieldName="Employee_ID" 
                VisibleIndex="3">
                <PropertiesComboBox DataSourceID="dsEmployee_ID" TextField="FullName" 
                    ValueField="Employee_ID">
                </PropertiesComboBox>
                <HeaderStyle HorizontalAlign="Center" />
            </dx:GridViewDataComboBoxColumn>
            <dx:GridViewDataDateColumn Caption="วันที่สั่ง" FieldName="Order_Date" 
                VisibleIndex="4">
                <PropertiesDateEdit DisplayFormatString="dd/MM/yyyy">
                </PropertiesDateEdit>
            </dx:GridViewDataDateColumn>
        </Columns>
        <SettingsDetail ShowDetailRow="True" />
        <Templates>
            <DetailRow>
                <dx:ASPxGridView ID="DetailGV" runat="server" AutoGenerateColumns="False" 
                    DataSourceID="dsOrder_manufaceture_List" KeyFieldName="Manufacture_List_NO" 
                    Width="100%" onbeforeperformdataselect="MasterGV_BeforePerformDataSelect">
                    <Columns>
                        <dx:GridViewCommandColumn VisibleIndex="11">
                            <EditButton Text="แก้ไข" Visible="True">
                            </EditButton>
                            <NewButton Visible="True" Text="เพิ่ม">
                            </NewButton>
                            <DeleteButton Text="ลบ" Visible="True">
                            </DeleteButton>
                            <ClearFilterButton Visible="True">
                            </ClearFilterButton>
                        </dx:GridViewCommandColumn>
                        <dx:GridViewDataTextColumn FieldName="Order_Manufacture_ID" Visible="False" 
                            VisibleIndex="0">
                            <EditFormSettings Visible="False" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="Manufacture_List_NO" Visible="False" 
                            VisibleIndex="1">
                            <EditFormSettings Visible="False" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataComboBoxColumn Caption="รายการผลิต" FieldName="Product_ID" 
                            VisibleIndex="3">
                            <PropertiesComboBox DataSourceID="dsProduct_ID" 
                                IncrementalFilteringMode="Contains" TextField="Product_Name" 
                                ValueField="Product_ID">
                            </PropertiesComboBox>
                        </dx:GridViewDataComboBoxColumn>
                        <dx:GridViewDataTextColumn FieldName="Amount_Product_Order" VisibleIndex="5" 
                            Caption="จำนวนที่สั่ง">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="Materrial_Damage" VisibleIndex="6" 
                            Caption="เสียหาย">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="Producted" VisibleIndex="9" 
                            Caption="คงเหลือ">
                            <EditFormSettings Visible="False" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="RowID" VisibleIndex="2" Caption="ลำดับ">
                            <EditFormSettings Visible="False" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataDateColumn Caption="วันที่ผลิต" FieldName="Date_of_manufacture" 
                            VisibleIndex="4">
                            <PropertiesDateEdit DisplayFormatString="dd/MM/yyyy">
                            </PropertiesDateEdit>
                        </dx:GridViewDataDateColumn>
                    </Columns>
                    <SettingsBehavior ConfirmDelete="True" />
                    <SettingsText ConfirmDelete="ยืนยันการลบ" />
                </dx:ASPxGridView>
            </DetailRow>
        </Templates>
    </dx:ASPxGridView>
    <asp:SqlDataSource ID="dsOrder_Manufacture" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
        DeleteCommand="DELETE FROM TB_Order_Manufacture WHERE (Order_Manufacture_ID = @Order_Manufacture_ID)" 
        InsertCommand="INSERT INTO TB_Order_Manufacture(Employee_ID, Order_Date) VALUES (@Employee_ID, @Order_Date)" 
        SelectCommand="SELECT Order_Manufacture_ID,ROW_NUMBER() OVER (ORDER BY TB_Order_Manufacture.Order_Manufacture_ID ) AS RowID, Order_Manufacture_doc_NO, Manufacture_Category_ID,Order_Date, Employee_ID FROM TB_Order_Manufacture" 
        
        UpdateCommand="UPDATE TB_Order_Manufacture SET Employee_ID = @Employee_ID, Order_Date = @Order_Date WHERE (Order_Manufacture_ID = @Order_Manufacture_ID)">
        <DeleteParameters>
            <asp:Parameter Name="Order_Manufacture_ID" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="Employee_ID" />
            <asp:Parameter Name="Order_Date" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="Employee_ID" />
            <asp:Parameter Name="Order_Date" />
            <asp:Parameter Name="Order_Manufacture_ID" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="dsOrder_manufaceture_List" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" SelectCommand="SELECT Order_Manufacture_ID,ROW_NUMBER() OVER (ORDER BY TB_Order_manufaceture_List.Manufacture_List_NO ) AS RowID, Manufacture_List_NO, Product_ID, Amount_Product_Order, Materrial_Damage, Producted, Date_of_manufacture FROM TB_Order_manufaceture_List

WHERE Order_Manufacture_ID = @Order_Manufacture_ID" 
        
        InsertCommand="INSERT INTO TB_Order_manufaceture_List(Order_Manufacture_ID, Product_ID, Amount_Product_Order, Materrial_Damage, Producted, Date_of_manufacture) VALUES (@Order_Manufacture_ID, @Product_ID, @Amount_Product_Order, @Materrial_Damage, @Amount_Product_Order - @Materrial_Damage, @Date_of_manufacture)" 
        DeleteCommand="DELETE FROM TB_Order_manufaceture_List WHERE (Manufacture_List_NO = @Manufacture_List_NO)" 
        
        UpdateCommand="UPDATE TB_Order_manufaceture_List SET Product_ID = @Product_ID, Amount_Product_Order = @Amount_Product_Order, Materrial_Damage = @Materrial_Damage, Producted = @Amount_Product_Order - @Materrial_Damage, Date_of_manufacture = @Date_of_manufacture WHERE (Manufacture_List_NO = @Manufacture_List_NO)">
        <DeleteParameters>
            <asp:Parameter Name="Manufacture_List_NO" />
        </DeleteParameters>
        <InsertParameters>
            <asp:SessionParameter Name="Order_Manufacture_ID" 
                SessionField="Order_Manufacture_ID" />
            <asp:Parameter Name="Product_ID" />
            <asp:Parameter Name="Amount_Product_Order" />
            <asp:Parameter Name="Materrial_Damage" />
            <asp:Parameter Name="Date_of_manufacture" />
        </InsertParameters>
        <SelectParameters>
            <asp:SessionParameter Name="Order_Manufacture_ID" 
                SessionField="Order_Manufacture_ID" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="Product_ID" />
            <asp:Parameter Name="Amount_Product_Order" />
            <asp:Parameter Name="Materrial_Damage" />
            <asp:Parameter Name="Date_of_manufacture" />
            <asp:Parameter Name="Manufacture_List_NO" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="dsEmployee_ID" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
        SelectCommand="SELECT Employee_ID, FirstName + ' ' + LastName AS FullName FROM TB_Employee">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="dsProduct_ID" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
        SelectCommand="SELECT Product_ID, Product_Name FROM TB_Product WHERE (Product_Category_ID = 01)">
    </asp:SqlDataSource>
    <dx:ASPxGridViewExporter ID="ASPxGridViewExporter1" runat="server" 
        ExportedRowType="Selected">
        <Styles>
            <Default Font-Names="Angsana New">
            </Default>
        </Styles>
        <PageHeader Right="[Pages #]
[Date Printed]">
        </PageHeader>
    </dx:ASPxGridViewExporter>
</asp:Content>
